﻿using System.Web;

namespace Sex
{
    public partial class Sex : System.Web.UI.Page
    {
        public class ListContext : MyList
        {
            string GetError(System.Exception e)
            {
                if (e == null) return strNoData;
                string s = "";
                s += FormatMyKey("Data") + FormatMyText("=") + GetDictionary(e.Data) + "<br/>";
                s += FormatMyKey("HelpLink") + FormatMyText("=") + e.HelpLink + "<br/>";
                s += FormatMyKey("InnerException") + FormatMyText("=") + e.InnerException.ToString() + "<br/>";
                s += FormatMyKey("Message") + FormatMyText("=") + e.Message + "<br/>";
                s += FormatMyKey("Source") + FormatMyText("=") + e.Source + "<br/>";
                s += FormatMyKey("StackTrace") + FormatMyText("=") + e.StackTrace + "<br/>";
                s += FormatMyKey("TargetSite.Name") + FormatMyText("=") + e.TargetSite.Name;
                return s;
            }
            string GetErrors(System.Exception[] e)
            {
                string s = "";
                for (int i = 0; i < s.Length; i++)
                    s += FormatMyKey("Error " + i.ToString().PadLeft(2, '0')) + "<br/>" + GetError(e[i]);
                return s;
            }
            public ListContext(State MyState)
                : base(MyState, "Context Object")
            {
                HttpContext c = HttpContext.Current;
                c.Items.Add(strDemoVariableName, strDemoEntry);

                Add("AllErrors", c.AllErrors==null ? "null" : c.AllErrors.Length.ToString());
                Add("Application", strSeeObject);
                Add("CurrentHandler", c.CurrentHandler.ToString());
                try
                {
                    Add("CurrentNotification", c.CurrentNotification.ToString());
                }
                catch
                {
                    Add("CurrentNotification", strRequiresPipelineMode);
                }
                Add("GetError", GetError(c.Error));
                Add("Handler", c.Handler.ToString());
                Add("IsCustomErrorEnabled", c.IsCustomErrorEnabled.ToString());
                Add("IsDebuggingEnabled", c.IsDebuggingEnabled.ToString());
                try
                {
                    Add("IsPostNotification", c.IsPostNotification.ToString());
                }
                catch
                {
                    Add("IsPostNotification", strRequiresPipelineMode);
                }
                Add("Items", GetDictionary(c.Items));
                Add("PreviousHandler", c.PreviousHandler == null ? strNoData : c.PreviousHandler.ToString());
                Add("Profile.UserName", c.Profile.UserName);
                Add("Request", strSeeObject);
                Add("Response", strSeeObject);
                Add("Server", strSeeObject);
                Add("Session", strSeeObject);
                Add("SkipAuthorization", c.SkipAuthorization.ToString());
                Add("Timestamp", c.Timestamp.ToString());
                Add("Trace.IsEnabled", c.Trace.IsEnabled.ToString());
                Add("Trace.TraceMode", c.Trace.TraceMode.ToString());
                Add("User.Identity.Name", c.User.Identity.Name);
            }
        }
    }
}